import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login.vue'
import Home from '@/views/Home.vue'
import Mine from '@/views/Mine.vue'
import CreatAdr from '@/views/CreatAdr.vue'
import EditAdr from '@/views/EditAdr.vue'
import managerAdr from '@/views/ManagerAdr.vue'
import Shop from '@/views/Shop.vue'
import Cart from '@/views/Cart.vue'
import Orders from '@/views/Orders.vue'
import ConfirmOrder from '@/views/ConfirmOrder.vue'
import editPerson from '@/views/editPerson.vue'
import NotFound from '@/views/NotFound.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/login',
      name:'Login',
      component:Login,
      
    },
    {
      path:'/',
      redirect:'/login'
    },
    {
      path:'/home',
      name:'home',
      component:Home,

    },
    {
      path:'/mine',
      component:Mine
    },
    {
      path:'/orders',
      component:Orders
    },
    {
      path:'/cart',
      component:Cart
    },
    {
      path:'/createadr',
      component:CreatAdr
    },
    {
      path:'/editAdr/:data',
      name:'editAdr',
      component:EditAdr
    },
    {
      path:'/manageradr',
      name:'manageradr',
      component:managerAdr
    },
    {
      path:'/Shop/:id',
      name:'Shop',
      component:Shop
    },
    {
      path:'/ConfirmOrder/:shopId/:data?',
      name:'ConfirmOrder',
      component:ConfirmOrder
    },
    {
      path:'/editPerson',
      name:'editPerson',
      component:editPerson
    },
    {
      path:'/*',
      name:'NotFound',
      component:NotFound
    }
  ]
})
router.beforeEach((to,from,next)=>{
  const {isLogin} = localStorage;
  (isLogin || to.name === 'Login')? next():next({name:'Login'})

})

export default router
